<?php


namespace app\service;


use app\dao\OrderDao;

class OrderService
{
    private $OrderDao;

    public function __construct()
    {
        $this->OrderDao = new OrderDao();
    }

    public function getOrder($id , $status = false){
        return $this->OrderDao->customQuery()->onlyTrashed($status)->filterById($id)->getOne();
    }

    public function getOrderByUserId($user_id , $status = false){
        return $this->OrderDao->customQuery()->onlyTrashed($status)->withDepositStatusAndRoomAndUsingRoomTime()->filterByUserId($user_id)->getAll();
    }

    public function addOrder($user_id , $pay_id , $room_id , $usingroom_time_id , $number , $deposit_status){
        return $this->OrderDao->save([
            'user_id' => $user_id,
            'pay_id' => $pay_id,
            'room_id' => $room_id,
            'usingroom_time_id' => $usingroom_time_id,
            'number' => $number,
            'deposit_status' => $deposit_status,
        ]);
    }

    public function editOrder($id , $data){
        $editData = [];
        empty($data['user_id']) || $editData['user_id'] = $data['user_id'];
        empty($data['pay_id']) || $editData['pay_id'] = $data['pay_id'];
        empty($data['room_id']) || $editData['room_id'] = $data['room_id'];
        empty($data['usingroom_time_id']) || $editData['usingroom_time_id'] = $data['usingroom_time_id'];
        empty($data['number']) || $editData['number'] = $data['number'];
        empty($data['deposit_status']) || $editData['deposit_status'] = $data['deposit_status'];

        return $this->OrderDao->edit($id , $editData);
    }

    public function delOrder($id){
        $this->OrderDao->delete($id);
        return;
    }
}